import base from 'js/config/base/base'
import equipment from './base/equipment'
import wuxing from 'js/config/base/wuxing'
import partner from 'js/config/base/partner'
import map from 'js/config/base/map'
import pet from 'js/config/base/pet'
import monster from './base/monster'
import battle from './base/battle'
import skillBook from './base/skillBook'
import gem from './base/gem'
import vip from './base/vip'
import soulMatrix from './base/soulMatrix'
import market from './base/market'
import task from './base/task'
import map_100001 from 'js/config/map/map_100001'
import partner_110001 from 'js/config/partner/partner_110001'
import monster_120001 from 'js/config/monster/monster_120001'
import monster_120002 from './monster/monster_120002'
import skill_130001 from 'js/config/skill/skill_130001'
import skill_130002 from 'js/config/skill/skill_130002'
import skill_130003 from 'js/config/skill/skill_130003'
import skill_130004 from 'js/config/skill/skill_130004'
import jinmai_150001 from './jinmai/jinmai_150001'
import door_140001 from './door/door_140001'
import vip_160002 from './vip/vip_160002'
import item_170001 from './item/item_170001'
import item_170002 from './item/item_170002'
import item_170003 from './item/item_170003'
import item_170004 from './item/item_170004'
import pet_180001 from './pet/pet_180001'
import buff_190001 from './buff/buff_190001'
import buff_190002 from './buff/buff_190002'
import item_170005 from './item/item_170005'
import task_210001 from './task/task_210001'
import item_170006 from './item/item_170006'
import formation_180001 from './formation/formation_180001'
import formation from './base/formation'
import treasure from './base/treasure'
import arena from './base/arena'
import suit from './base/suit'
import talent from './base/talent'
import bar from './base/bar'
import task_210002 from './task/task_210002'
import alchemy_310001 from './alchemy/alchemy_310001'
import town from './town/town'
import titles_230001 from './titles/titles_230001'
import map_100002 from './map/map_100002'
import newland from './newland/newland'
// 所有模板信息

interface templatePropName {
    [id: number]: string
}
interface templatePropInfo {
    [id: number]: string
}
interface templateTotalConfigByID {
    [id: number]: any
}

export let propName: any = {
    gold: '金币',
    diamond: '魂晶',
    diamond2: '异石',
    exp: '经验',
    skillExp: '进阶经验'
} //发送给客户端的信息 id => name
export let configByID: templateTotalConfigByID = {}


function getTemplateByTID(templateInfos: any[]) {
    let data = {}
    for (let j = 0; j < templateInfos.length; j++) {
        let templateInfo = templateInfos[j]
        let temp = {}
        for (let i in templateInfo) {
            temp[i] = templateInfo[i]
            let id = parseInt(i)
            temp[i]['tID'] = id
            temp[i]['type'] = Math.floor(id / 10000)
            temp[i]['subType'] = Math.floor(id % 10000 / 100)
            if (templateInfo[i].name) {
                propName[i] = templateInfo[i].name
            }
        }
        (<any>Object).assign(data, temp)
    }
    return data
}

export let gameConfig = {
    base,
    wuxing,
    equipment,
    partner,
    map,
    pet,
    monster,
    battle,
    skillBook,
    gem,
    vip,
    soulMatrix,
    market,
    task,
    maps: getTemplateByTID([map_100001, map_100002]),
    partners: getTemplateByTID([partner_110001]),
    monsters: getTemplateByTID([monster_120001,monster_120002]),
    skill: getTemplateByTID([skill_130001, skill_130002, skill_130003,
        skill_130004]),
    jingMais: getTemplateByTID([jinmai_150001]),
    doors: getTemplateByTID([door_140001]),
    vips: getTemplateByTID([vip_160002]),
    items: getTemplateByTID([item_170001, item_170002, item_170003, item_170004, item_170005]),
    equips: getTemplateByTID([item_170002]),
    treasures: getTemplateByTID([item_170003]),
    pets: getTemplateByTID([pet_180001]),
    buffs: getTemplateByTID([buff_190001, buff_190002]),
    skillBooks: getTemplateByTID([item_170004]),
    skills: getTemplateByTID([skill_130002]),
    auxiliarySkills: getTemplateByTID([skill_130003]),
    tasks: getTemplateByTID([task_210001]),
    askillBooks: getTemplateByTID([item_170006]),
    formation: getTemplateByTID([formation_180001]),
    campTask: getTemplateByTID([task_210002]),
    baseFormation: formation,
    treasure,
    arena,
    suit,
    talent,
    bar,
    town,
    newland,
    alchemy: getTemplateByTID([alchemy_310001]),
    titles: getTemplateByTID([titles_230001])
}



for (let data of (<any>Object).values(gameConfig)) {
    for (let [id, value] of (<any>Object).entries(data)) {
        configByID[id] = value
    }
}
let configByIDStr = JSON.stringify(configByID)
let gameConfigStr = JSON.stringify(gameConfig)

export let gameConfigHandle = {
    gameConfig,
    propName,
    configByID,
    setConfigByID: () => {
        let data = JSON.parse(configByIDStr)
        gameConfigHandle.configByID = data

    },
    setGameConfig: () => {
        let data = JSON.parse(gameConfigStr)
        gameConfigHandle.gameConfig = data
    }
}